package zy.blue7.doscan;

import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;

import java.util.Set;

/**
 * @author blue7
 * @version 1.0
 * @date 2021/7/26 15:29
 *
 * todo 定义一个扫描器，指定要扫描的标识，即注解
 */
public class ZYClassPathBeanDefinitionScanner extends ClassPathBeanDefinitionScanner {

	public ZYClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters) {
		super(registry, useDefaultFilters);
	}

	public void resetFilters() {
		/**
		 * todo 满足任意 includeFilter 会被加载
		 */
		addIncludeFilter(new AnnotationTypeFilter(ZYService.class));

		/**
		 * todo 满足任意 includeFilter 不会被加载,下面的代码不能加上，不然就直接排除指定的注解
		 */
//		addExcludeFilter(new AnnotationTypeFilter(ZYService.class));
	}


	/**
	 * todo 重写类扫描包路径加载器，调用父类受保护的扫描方法 doScan
	 * @param basePackages
	 * @return
	 */
	@Override
	protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
		return super.doScan(basePackages);
	}
}
